﻿using FarmSmartSleep.Common.Domain.PM;
using FarmSmartSleep.Common.Domain.BeginTable;
using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Organ.API.Application.ProductionManagement.FemaleRen;
using FarmSmartSleep.Organ.API.Application.ProductionManagement.MotherGivingBirthFile;
using FarmSmartSleep.Organ.API.Application.ProductionManagement.SelectFile;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Yitter.IdGenerator;
using FarmSmartSleep.Organ.API.Application.ProductionManagement.EweHistoryCommands;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
using FarmSmartSleep.Organ.API.Application.ProductionManagement.MotherWeaningFile;
using FarmSmartSleep.Common.Domain.PM.select;
using FarmSmartSleep.Organ.API.Application.ProductionManagement.MotherHybridizationCommands;
using FarmSmartSleep.Organ.API.Application.ProductionManagement.LambWeaningCommands;
using FarmSmartSleep.Organ.API.Application.ProductionManagement.SheepTransferCommands;

namespace FarmSmartSleep.Organ.API.Controllers
{
    /// <summary>
    /// 生产管理控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductionManagementController : ControllerBase
    {
        private readonly IMediator mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public ProductionManagementController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        #region 公共方法

        /// <summary>
        /// 雪花Id
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public string GetId()
        {
            return YitIdHelper.NextId().ToString();
        }
        /// <summary>
        /// 分娩难易度
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result> ParturitionDifficultyList()
        {
            return await mediator.Send(new ParturitionDifficultyListCommon());
        }
        /// <summary>
        /// 肥羊批次
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns> 
        [HttpGet]
        public async Task<Result> FatSheepBatchList()
        {
            return await mediator.Send(new FatSheepBatchListCommon());
        }

        /// <summary>
        /// 耳号反填
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultT<SleepInfor>> EarMasList([FromQuery] EarMasListCommon request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 单删
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns> 
        [HttpGet]
        public async Task<Result> MotherGivingBirthDDelete([FromQuery] MotherGivingBirthDDeleteCommon request)
        {
            return await mediator.Send(request);
        }

        #endregion

        #region 母羊妊检新增
        /// <summary>
        /// 母羊妊检新增
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>

        [HttpPost]
        public async Task<Result> Handle(FemaleRenCreateCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        #endregion

        #region 母羊妊检记录查询
        /// <summary>
        /// 母羊妊检记录查询
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> Handle1(FemaleRenSelectCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 母羊妊检删除
        /// <summary>
        /// 批量删除妊检信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<Result> Handle2(FemaleRenDeleteCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        #endregion

        #region 母羊妊检反填
        /// <summary>
        /// 反填母羊妊检信息方法
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<ResultT<EwePregnancyCheckRecord>> Handle3(FemaleRenDetailCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        #endregion

        #region 母羊妊检修改
        /// <summary>
        /// 修改母羊妊检信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<Result> Handle4(FemaleRenUpdateCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        #endregion

        #region 妊检结果下拉框
        /// <summary>
        /// 妊检结果下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<Result> Handle5()
        {
            FemaleRenResultCommand command = new FemaleRenResultCommand();
            return await mediator.Send(command);
        }
        #endregion

        #region 妊检方式下拉框
        /// <summary>
        /// 妊检方式下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public Task<Result> Handle6()
        {
            FemaleRenWayCommand command = new FemaleRenWayCommand();
            return mediator.Send(command);
        }
        #endregion

        #region 母种分娩
        /// <summary>
        /// 种母分娩新增
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> MotherGivingBirthAdd(MotherGivingBirthCreateCommon request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 种母分娩列表查询
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultPage<List<MotherGivingBirthListDto>>> MotherGivingBirthList([FromQuery] MotherGivingBirthListCommon request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 种母分娩修改
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> MotherGivingBirthUpdate(MotherGivingBirthUpdateCommon request)
        {
            return await mediator.Send(request);
        }

        #endregion

        #region 种母断奶
        /// <summary>
        /// 种母分娩新增
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> MotherWeaningCreate(MotherWeaningCreateCommon request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 种母分娩列表查询
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultPage<List<MotherWeaningListDto>>> MotherWeaningList([FromQuery] MotherWeaningListCommon request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 母羊历史


        /// <summary>
        /// 母羊历史新增
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("EweHistoryCreate")]
        public async Task<Result> Handle(EweHistoryCreateCommand request)
        {
            return await mediator.Send(request);
        }
        #region 种母配种
        /// <summary>
        /// 获取种母配种方式
        /// </summary>
        /// <param name="cmd">获取种母配种方式请求对象</param>
        [HttpGet]
        public async Task<ResultT<HybridizationType>> SearchHybridizationTypes([FromQuery] HybridizationTypeSearchCommand cmd)
        { return await mediator.Send(cmd); }

        /// <summary>
        /// 获取种母发情类型
        /// </summary>
        /// <param name="cmd">获取种母发情类型请求对象</param>
        /// <returns>返回种母发情类型数据集合</returns>
        [HttpGet]
        public async Task<ResultT<EstrusType>> SearchEstrusTypes([FromQuery] EstrusTypeSearchCommand cmd)
        { return await mediator.Send(cmd); }


        #endregion


        /// <summary>
        /// 母羊历史列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("EweHistorySelect")]
        public async Task<Result> Handle(EweHistorySelectCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 种母配种

        /// <summary>
        /// 种母配种
        /// </summary>
        /// <param name="cmd">种母配种方法请求对象</param>
        /// <returns>种母配种响应对象</returns>
        [HttpPost]
        public async Task<Result> MotherHybidizationAdd(MotherHybridizationCreateCommand cmd)
        { return await mediator.Send(cmd); }


        /// <summary>
        /// 查询配种种母信息方法
        /// </summary>
        /// <param name="cmd">查询配种种母信息方法请求对象</param>
        /// <returns>查询配种种母信息方法响应对象</returns>
        [HttpPost]
        public async Task<ResultT<MotherHybidizationListDto>> MotherListSearch(MotherBatchSearchCommand cmd)
        {
            return await mediator.Send(cmd);
        }


        /// <summary>
        /// 分页查询种母配种信息
        /// </summary>
        /// <param name="cmd">分页查询种母配种信息请求对象</param>
        /// <returns>分页查询种母配种信息响应对象</returns>
        [HttpPost]
        public async Task<ResultPage<MotherHybirdizationSearchDto>> MotherHybridizationSearch(MotherHybridizationSearchCommand cmd)
        { return await mediator.Send(cmd); }


        /// <summary>
        /// 删除配种信息（批量）
        /// </summary>
        /// <param name="cmd">删除配种信息请求对象</param>
        /// <returns>删除配种信息响应对象</returns>
        [HttpDelete]
        public async Task<Result> MotherHybridizationAllDelete(MotherHybridizationAllDeleteCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 反添配种信息
        /// </summary>
        /// <param name="request">反添配种信息请求对象</param>
        /// <param name="cancellationToken"></param>
        /// <returns>反添配种信息响应对象</returns>
        [HttpPost]
        public async Task<ResultT<MotherHybridization>> MotherHybridizationDetail(MotherHybridizationDetailCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 修改配种信息
        /// </summary>
        /// <param name="cmd">修改配种信息请求对象</param>
        /// <returns>修改配种信息响应对象</returns>
        [HttpPut]
        public async Task<Result> MotherHybridizationUpdate(MotherHybridizationUpdateCommand cmd)
        { return await mediator.Send(cmd); }


        #endregion

        #region 羊只转舍

        /// <summary>
        /// 添加羊只转舍信息
        /// </summary>
        /// <param name="cmd">添加羊只转舍信息强求对象</param>
        /// <returns>添加羊只转舍信息响应对象</returns>
        [HttpPost]
        public async Task<Result> SheepTransferCreate(SheepTransferCreateComand cmd)
        { return await mediator.Send(cmd);}

        /// <summary>
        /// 分页查询转舍信息
        /// </summary>
        /// <param name="cmd">分页查询转舍信息请求对象</param>
        /// <returns>分页查询转舍信息响应对象</returns>
        [HttpPost]
        public async Task<ResultPage<SheepTransListDto>> SheepTransSearch(SheepTransferSearchCommand cmd)
        { return await mediator.Send(cmd);}


        /// <summary>
        /// 获取转舍类型
        /// </summary>
        /// <param name="cmd">获取转舍类型请求对象</param>
        /// <returns>返回转舍类型信息</returns>
        [HttpGet]
        public async Task<Result> SheepTransferTypeSearch([FromQuery]SheepTransferTypeSearchCommand cmd)
        { return await mediator.Send(cmd);}



        #endregion

        #region 羊羔断奶

        /// <summary>
        /// 羔羊断奶添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("LambWeaningCreate")]
        public async Task<Result> Handle(LambWeaningCreateCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 羔羊列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("LambWeaningSelect")]
        public async Task<Result> Handle(LambWeaningSelectCommand request)
        {
            return await mediator.Send(request);
        }
    }
    #endregion
}
